import {observable,action} from 'mobx';
import {WeaForm, WeaSwitch} from 'comsMobx';
import * as DecisionAPI from '../apis/decision';
import {WeaTableNew} from 'comsMobx'
const {TableStore} = WeaTableNew;
import {message} from 'antd';

import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

export default class Decision {
    @observable userList = [];
    @observable title =  getLabel(384791,'会议任务');
    @observable loading =  false;

    @observable searchParamsAd = {};
    @observable showSearchAd = false;
    @observable fields = {};
    @observable dataKey = "";
    @observable meetingid = "";
    @observable enddate = "";
    @observable topTab = [];
    @observable showNew = false;
    @observable previewMeetingId = '';

    @observable deciScope = 0;//指定当前在哪个tab页

    @observable conditioninfo = [];
    // @observable tableStore = new TableStore();
    @observable tableStore = {};


    //高级搜素的form
    @observable adSearchForm = new WeaForm();


    constructor() {

    }

    @action
    addUser(params) {
        this.userList.push({name: "dyf"});
    }

    getUserList(params) {
        return this.userList.slice();
    }



    @action doLoading = params => {
        this.loading =  true;
            //调用API
            DecisionAPI.getDatas(params).then(action((data) => {
                this.tableStore = {...this.tableStore, [data.sessionkey]:new TableStore()}
                this.tableStore[data.sessionkey].getDatas(data.sessionkey,  1);
                this.loading =  false;
                this.dataKey = data.sessionkey;
            }));
    }

//初始化会议查询页查询条件
    @action initDatas = params => {
        DecisionAPI.getCondition(params).then(action((data) => {
            const { groupinfo, conditioninfo } = data;
            this.adSearchForm = new WeaForm();
            this.adSearchForm.initFormFields(conditioninfo);
            this.conditioninfo = conditioninfo;
            this.topTab = groupinfo;
            this.deciScope=0;
        }));
    }


    //高级搜索受控
    @action setShowSearchAd = bool =>{
        this.showSearchAd = bool;
    }


    //高级搜索表单内容
    @action saveFields = (value = {}) => {
        this.fields = value;
        this.searchParamsAd = function(){
            let params = {};
            if(value){
                for (let key in value) {
                    params[value[key].name] = value[key].value
                }
            }
            return params
        }();
    }

    //任务完成
    @action Done = (params,searchParamsAd) => {
        //调用API
        DecisionAPI.overCalendarItem(params).then(action((result)=>{
            if(result.ret == true){
              message.success(`${getLabel(4714, '操作成功')}`);
              searchParamsAd = {...searchParamsAd,deciScope:this.deciScope}
              this.doLoading(searchParamsAd);
            }else {
              message.success(`${getLabel(4715, '操作失败')}`);
            }
        }));
    }


    @action savePreviewMeetingId = (value={}) => {
           this.previewMeetingId = value.meetingid;
    }

}